﻿using Basic.FlowDAL;
using Basic.FlowModel.DB;
using Basic.FlowRemoteModel.NodeMsg.Model;
using WeDonekRpc.Helper;

namespace Basic.FlowCollect.lmpl
{
    internal class NodeMsgCollect : INodeMsgCollect
    {
        private readonly IFlowNodeMsgDAL _BasicDAL;

        public NodeMsgCollect ( IFlowNodeMsgDAL basicDAL )
        {
            this._BasicDAL = basicDAL;
        }
        public DBFlowNodeMsg Get ( long id )
        {
            return this._BasicDAL.Get(id);
        }
        public bool Set ( DBFlowNodeMsg sour, NodeMsgSet data )
        {
            return this._BasicDAL.Update(sour, data);
        }
        public void Add ( NodeMsgSet data )
        {
            this._BasicDAL.Add(data);
        }
        public void Clear ( long flowId )
        {
            long[] ids = this._BasicDAL.Gets(a => a.FlowId == flowId, a => a.Id);
            if ( !ids.IsNull() )
            {
                this._BasicDAL.Delete(ids);
            }
        }
        public void Clear ( long flowId, long nodeId )
        {
            this._BasicDAL.Clear(flowId, nodeId);
        }
        public Result[] GetsByNode<Result> ( long nodeId ) where Result : class, new()
        {
            return this._BasicDAL.Gets<Result>(a => a.NodeId == nodeId);
        }
        public Result[] Gets<Result> ( long flowId ) where Result : class, new()
        {
            return this._BasicDAL.Gets<Result>(a => a.FlowId == flowId);
        }

        public void Delete ( DBFlowNodeMsg msg )
        {
            this._BasicDAL.Delete(msg.Id);
        }
    }
}
